package com.woniu.secondhand.controller;

import com.woniu.common.entity.Result;
import com.woniu.secondhand.entity.vo.CategoryIndexVO;
import com.woniu.secondhand.service.ISecondhandCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author HMMT
 * @since 2023-05-20
 */
@RestController
@RequestMapping("/secondhandCategory")
@Api(tags = "分类管理")
@Slf4j
public class SecondhandCategoryController {
    @Autowired
    private ISecondhandCategoryService categoryService;

    @GetMapping("/first")
    @ApiOperation("搜索所有一级分类")
    public Result<List<CategoryIndexVO>> listAllFirstCategories() {
        List<CategoryIndexVO> categoryIndexVOList = categoryService.listAllFirst();
        return Result.ok(categoryIndexVOList);
    }

    @GetMapping("/relation/{parentId}")
    @ApiOperation("根据父ID级联查询分类信息")
    public Result<CategoryIndexVO> getCategoryByParentId(@PathVariable Integer parentId) {
        CategoryIndexVO categoryIndexVO = categoryService.getCategoryByParentId(parentId);
        return Result.ok(categoryIndexVO);
    }

}
